# JSZ Translator Installation Script
# PowerShell version

Write-Host "Installing JSZ Translator..." -ForegroundColor Green
Write-Host ""

# 设置目标目录
$TARGET_DIR = "D:\rsoft\mybin\bin"

# 检查目标目录是否存在
if (-not (Test-Path $TARGET_DIR)) {
    Write-Host "Error: Target directory $TARGET_DIR does not exist." -ForegroundColor Red
    Write-Host "Please create the directory first or update the TARGET_DIR variable." -ForegroundColor Red
    Read-Host "Press Enter to exit"
    exit 1
}

# 检查源文件是否存在
if (-not (Test-Path "build\jsz_translator.exe")) {
    Write-Host "Error: jsz_translator.exe not found in build directory." -ForegroundColor Red
    Write-Host "Please compile the project first using build.bat" -ForegroundColor Red
    Read-Host "Press Enter to exit"
    exit 1
}

try {
    # 复制可执行文件
    Write-Host "Copying jsz_translator.exe to $TARGET_DIR..." -ForegroundColor Yellow
    Copy-Item "build\jsz_translator.exe" $TARGET_DIR -Force

    # 复制配置文件
    Write-Host "Copying configuration files..." -ForegroundColor Yellow
    $configFiles = @(
        "keywords.conf",
        "messages.conf", 
        "messages_en.conf",
        "messages_zh.gbk.conf",
        "simple.conf"
    )

    foreach ($file in $configFiles) {
        $sourcePath = "build\$file"
        if (Test-Path $sourcePath) {
            Copy-Item $sourcePath $TARGET_DIR -Force
            Write-Host "  - Copied $file" -ForegroundColor Gray
        } else {
            Write-Host "  - Warning: $file not found, skipping" -ForegroundColor Yellow
        }
    }

    Write-Host ""
    Write-Host "Installation completed successfully!" -ForegroundColor Green
    Write-Host ""
    Write-Host "Files installed to: $TARGET_DIR" -ForegroundColor Cyan
    Write-Host "- jsz_translator.exe" -ForegroundColor Gray
    foreach ($file in $configFiles) {
        if (Test-Path "build\$file") {
            Write-Host "- $file" -ForegroundColor Gray
        }
    }
    Write-Host ""
    Write-Host "You can now run 'jsz_translator' from any directory." -ForegroundColor Green
    Write-Host ""

} catch {
    Write-Host "Error during installation: $($_.Exception.Message)" -ForegroundColor Red
    Read-Host "Press Enter to exit"
    exit 1
}

Read-Host "Press Enter to exit"